package com.situ.bas.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.bas.service.BasDictService;
import com.situ.bas.entity.BasDict;
import com.situ.util.*;

import java.util.List;

/**
 * BasDict的路由接口服务
 * 
 * @author 
 *
 */
@RestController
public class BasDictController {

	/** BasDictService服务 */
	@Autowired
	private BasDictService basDictService;
	
	/**
	 * 查询所有BasDict数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryBasDict", produces = {"application/json;charset=UTF-8"})
	public ResponseData find(BasDict value) {

		return ResponseData.ok().putDataValue("list",basDictService.find(value));
	}
	
	/**
	 * 通过id查询BasDict数据的方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "queryBasDictById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData findOne(@PathVariable(name="id") Integer id) {
		 return ResponseData.ok().putDataValue("obj",basDictService.findOne(id));
	}
	
	/**
	 * 插入BasDict属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "saveBasDict")
	public ResponseData save(BasDict value) {
		return ResponseData.ok().putDataValue("obj", basDictService.saveNotNull(value));
	}
	
	/**
	 * 更新BasDict属性不为空的数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "updateBasDict", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(BasDict value) {
		return ResponseData.ok().putDataValue("obj",basDictService.updateNotNullById(value));
	}

	/**
	 * 通过id删除BasDict数据方法
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "delBasDictById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delete(@PathVariable(name="id") Integer id) {
		return ResponseData.ok().putDataValue("obj",basDictService.deleteById(id));
	}

	@RequestMapping(value = "queryBasDictBYlike", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(BasDict value,
							  @RequestParam(defaultValue ="1", required = false) int startPage ,
							  @RequestParam(defaultValue = "15",required = false) int PageSize) {
		PageHelper.startPage(startPage,PageSize );
		List<BasDict> list = basDictService.findbylike(value);
		PageInfo pageInfo=new PageInfo(list,5);
		return ResponseData.ok().putDataValue("pageInfo",pageInfo);
	}


	@RequestMapping(value = "querytype", produces = {"application/json;charset=UTF-8"})
	public ResponseData querytype(String value){
				return ResponseData.ok().putDataValue("list",basDictService.querytype(value) );
	}
}
